package org.twf.aicodehelper.controller;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.twf.aicodehelper.service.IAiCodeHelperMemoryService;
import reactor.core.publisher.Flux;

@Controller
@RequestMapping("/ai")
public class AiController {


    @Resource
    @Qualifier("WebAndStreamService")
    private IAiCodeHelperMemoryService webAndStreamService;


    /**
     * 流式会话输出
     *
     * @param memoryId
     * @param message
     * @return
     */
    @GetMapping("/chat")
    public Flux<ServerSentEvent<String>> chat(String memoryId, String message) {
        return webAndStreamService.chatStream(memoryId, message).map(
                chunk -> ServerSentEvent.<String>builder()
                        .data(chunk)
                        .build()
        );
    }

}
